package com.imon.web.codesphere.resources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.imon.web.codesphere.DiffData;

@Component
@Path("/diffview")
public class DiffViewResource extends ResourceBase {

	private static final Log LOG = LogFactory.getLog(DiffViewResource.class);

	@GET
	@Path("/{revision}")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getDiff(@PathParam("revision") final long revision, @QueryParam("old") final long oldRevision,
			@QueryParam("path") final String path) {
		LOG.debug(String.format("getDiff(%s, %s, %s)", revision, oldRevision, path));

		final DiffData diffData = getDiffProcessor().createDiff(path, oldRevision, revision);

		final String json = getJsonParser().getJson(diffData);
		return Response.ok(json).build();
	}
}